<?php

/**
 * video actions.
 *
 * @package    wills
 * @subpackage video
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class videoActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->pager = new sfDoctrinePager(
      'Video',
      sfConfig::get('app_per_page_video')
    );
    $this->pager->setQuery(Doctrine::getTable('Video')->createQuery('a'));
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();

    $this->videos = $this->pager->getResults();
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->video = Doctrine::getTable('Video')->find(array($request->getParameter('id')));
    $this->forward404Unless($this->video);
    //
    if($tag=$this->video->getTag())
	  {
		  $this->relatedvideos = Doctrine::getTable('Video')
			  ->createQuery('a')
		    ->addWhere('tag LIKE ?', '%'.$tag.'%')
			  ->addWhere('id != ?',$this->video->getId())
			  ->limit(2)
		    ->execute();
	  }
  }


  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $video = $form->save();

      $this->redirect('video/edit?id='.$video->getId());
    }
  }
}
